var xx='Narcis';
var I=JavaImporter(org.zeroes.common_prelude,com.zeroes.cons,org.zeroes.svg,org.zeroes.Events,org.zeroes.Components);
var s=null;
var ss2=null;
var ani=null;
var grup=null;
var txt=null;
var canrotate=false;
var g=game;
with(I)
{

events.on('*.maka.*',function(a,e){
		var u=new Util();
		java.lang.System.err.println(a+xx+u.fun());
	});

events.on('kaka.*.*',function(a,e){
	java.lang.System.err.println(a+' alta functie');
	
});
events.on('sys.resumed.*',function(a,e){
	
	java.lang.System.err.println('GAME RESUMED JAVASCRIPT ');
});
events.on("sys.computed.*",function(a,e){
var r=e.complements.get(0);
var fr=e.castToInteger(r);
if(canrotate)
	txt.newText(fr);
		//java.lang.System.err.println('Frame rate: '+fr);
	})
	
events.on("*.tick.*",function(a,e){
//var r=e.complements.get(0);
//var fr=e.castToFloat(r);

//	java.lang.System.err.println('Update rate: '+fr);
})

var selected;
var savedx=0,
    savedy=0;
events.on("*.Accelerometer.*",function(a,e){
	var r=e.who;
	var rr=e.castToVertex3(r);
	java.lang.System.err.println('Acc data: '+rr.x+' '+rr.y+' '+rr.z);
});
events.on("*.touch.up",function(a,e){
	//var poz = e.castToVector2D(e.who);
	//ZSGameManager.AskMe().pauseCurrentGame();
	/*var mt = new ZSBMoveTo("amove",s,0,1,ZSBehavior.LINEAR);
	//mt.FrameRateDependant=true;
	mt._("run", PARAM.$("I:2000,I:410,I:10,S:>"));*/
	
	//var rt = new ZSBRotateTo("arot",s,0,1,ZSBehavior.ELASTIC_IN);
	//rt.FrameRateDependant=true;
	//rt._("run", PARAM.$("I:2000,I:100,S:>"));
	
	//var st = new ZSBScaleTo("ascale",s,0,1,ZSBehavior.LINEAR);
	//st.FrameRateDependant=true;
	//st._("run", PARAM.$("I:2000,F:0.5,F:0.5,S:>"));
	
	//var fade = new ZSBFade("_fade",s,1000,10,ZSBehavior.LINEAR);
	//fade.FrameRateDependant=true;
	//fade._("run", PARAM.$("I:2700,S:>"));
	
	//var along = new ZSBMoveAlongPath("path",s,0,1,ZSBehavior.LINEAR);
	//along.FrameRateDependant=true;
	//along._("run", PARAM.$("I:8000,S:poteca,S:<"));
	
 
//ani.backToInitialFrame=true;
//	ani._("run", PARAM.$("I:17"));
	//ani.stopMe();
	/*var bl1 =game.getLayerByTitle("Background");
	var tex1 = new ZSTexture2D(game.ctx.getResources().openRawResource(R.raw.construct2));
	var spr1 = new ZSSprite(tex1);
	bl1.addSprite(spr1);
	spr1.tag="kiki";
	spr1.setPosition(50,50);
bl1.SocialDirty=true;*/
	//game.setCurrentSprite(null);
	//selected=null;
	//game.once=true;
//	java.lang.System.err.println('TOUCH UP '+e.name+' '+poz.x+' '+poz.y+' '+e.loopindex);
	
});
events.on("text.RotateTo.finished",function(a,e){
	//var mt = new ZSBMoveTo("amove",s,1000,2,ZSBehavior.LINEAR);
	//mt.FrameRateDependant=true;
	//mt._("run", PARAM.$("I:1000,I:410,I:10,S:>"));
});


events.on("*.touched.up",function(a,e){

	game.setCurrentSprite(null);
	selected=null;
	java.lang.System.err.println('TOUCHED UP... '+e.name);
	

	
});

events.on("*.touch.drag",function(a,e){
	var poz = e.castToVector2D(e.who);
	//game.once=true;
	java.lang.System.err.println('DRAG :  '+e.name+' '+poz.x+' '+poz.y);
	//var selected=game.getCurrentSprite();
	if(selected&&selected.tag=='text'){

		selected.setPosition(savedx+poz.x,savedy+poz.y);
		
	}
	
});



events.on("*.touch.down",function(a,e){
	
	//var poz = e.castToVector2D(e.who);
	//game.setCurrentSprite(null);
	//game.once=true;
	//java.lang.System.err.println('TOUCH DOWN '+e.name+' '+poz.x+' '+poz.y+' '+e.loopindex);
	
});


events.on("text.touched.down",function(a,e){
	/*events.makeOnce("sys.touched.all",function(a,i){
		
		var poz = new ZSPair(game.lt,"");
		var ev = new ZSEvent(a,poz,i);
		events._(a,ev);
		
	})*/
	selected=game.getCurrentSprite();
	if(selected){
	
			savedx=selected.position.x;
			savedy=selected.position.y;
			
	}
	java.lang.System.err.println('ITEM TOUCHED '+a);
	
});
events.on("text.touched.up",function(a,e){
	//ZSGameManager.AskMe().pauseCurrentGame();
	ZSGameManager.AskMe().toEXIT();
})

events.on("steluta 1.touched.up",function(a,e){
	game.EndLevel("Level 1");
	//ani.stopMe();
	//game.$('sigla').setPosition(1200,0);
	//game.$('sigla').rotateClockwise(45);
});

events.on("text.touched.up",function(a,e){
	s.Layer().removeSprite(s);
	
	//ani.resume();
	//game.$('sigla').setPosition(300,300);
	//game.$('sigla').rotateClockwise(45);
});

events.on("sigla.touched.up",function(a,e){
/*var ns = new ZSSprite(R.raw.construct2);
ns.tag="oarece";
var tal = game.getLayerByTitle("Background");
tal.addGroupedSprite(ns,"FAMILIE");
ns.$Position(400, 240);*/
//var along = new ZSBMoveAlongPath("path",ns,0,1,ZSBehavior.LINEAR);
//along.FrameRateDependant=true;
//along._("run", PARAM.$("I:12000,S:cale,S:>"));
//canrotate=true;
//tal.getGroupNamed('FAMILIE').translate(1200,0);
/*	var tal = game.getLayerByTitle("Background");

txt = new ZSLabel('NARCIS',"BOLD",36,[255,0,255,0],150);
txt.tag="txt";
tal.addGroupedSprite(txt,'FAMILIE');
txt.$Position(400, 240);*/
	var tal = game.getLayerByTitle("Background");
	var fade = new ZSBLayerFade("_fade",tal,1000,10,ZSBehavior.LINEAR);
	//fade.FrameRateDependant=true;
	fade._("run", PARAM.$("I:2700,S:<"));

});

events.on("text.MoveTo.finished",function(a,e){
	java.lang.System.err.println('TERMINAT .... '+game.getComponentCount());
});
events.on("text.MoveTo.start",function(a,e){
	java.lang.System.err.println('START .... '+game.getComponentCount());
});
events.on("text.collideWith.scorimage",function(a,e){
	//java.lang.System.err.println('OUCH OUCH ....');
	//game.$('steluta 1').rotateClockwise(45);
});

events.on("*.gameStart.*",function (a,e){
	//game.lt=new vector2(0,0);
	s=g.$('sigla');
	grup=g.$('steluta 1').Group();
	//s.setOpacity(0);
	//s.rotateClockwise(31.5);
	/*var tex = new ZSTexture2D(game.ctx.getResources().openRawResource(R.raw.construct2));
	var bl = new ZSBatchLayer("B",game,tex);
	game.addLayer(bl);
	bl.addRect(new Rect(0,0,128,128,"rotita"));
	bl.addRect(new Rect(128,0,256,128,"_rotita"));
	
	var ss = new ZSSprite("r1",bl.rectById("rotita"));
	var ss1 = new ZSSprite("r2",bl.rectById("_rotita"));
	bl.addSprite(ss);
	bl.addSprite(ss1);
	ss.setPosition(64, 164);
	ss1.setPosition(500, 64);*/
	//grup = game.getLayerByTitle("Background");
	/*var tal = game.getLayerByTitle("ANIM");
	ss2 = new ZSSprite("w0",tal.rectById("w-0"));
	tal.addSprite(ss2);
	ss2.setPosition(150, 300);
	//ani = new ZSBAnimation("animatie",ss2,ZSCondition.LOOP_FOREVER);
	//ani._("run", PARAM.$("I:1"));
	ani = new ZSBScaleTo("ascale",s,0,ZSCondition.LOOP_FOREVER,ZSBehavior.LINEAR);
	//st.FrameRateDependant=true;
	ani._("run", PARAM.$("I:2000,F:0.5,F:0.5,S:>"));*/
})


events.on("sys.EndLevel.*",function(a,e){
	
	java.lang.System.err.println('The end ... !');

})

};